import { NetworkUtil } from "../../vv/utils/NetworkUtil";
import { Player } from "./bean/Player";

//游戏API地址
export class ApiUrl {
    public static readonly baseUrl: string = "https://www.iafeng.cc/api/"; //项目域名
    public static readonly showPlayerInfo: string = ApiUrl.baseUrl + "showPlayerInfo"; //查询用户基础面板信息
}

//游戏UI数据
export class testData {
    //当前地图可刷新资源
    public static getResourceData(id: number) {
        //pos坐标 mapId地图ID itemId物品ID rowId物品在结构中唯一编号 count本组数量 lv物品等级 rare稀有度（1~0越小越难得）title物品名 remark物品描述
        let map: Map<Number, Array<any>> = new Map();

        let pos = [];
        let mapId = 1;
        pos.push({ pos: [159.33, 199.162], mapId: mapId, rowId: 1, itemId: 1, count: 1, lv: 1, rare: 1, title: "花生", remark: "好吃的花生" });
        pos.push({ pos: [-208.272, -239.303], mapId: mapId, rowId: 2, itemId: 2, count: 1, lv: 2, rare: 0.8, title: "奶酪", remark: "美味的奶酪" });
        pos.push({ pos: [216.907, -544.9], mapId: mapId, rowId: 3, itemId: 3, count: 1, lv: 2, rare: 0.5, title: "樱桃", remark: "香甜的水果" });
        pos.push({ pos: [169.33, 99.162], mapId: mapId, rowId: 4, itemId: 1, count: 2, lv: 1, rare: 1, title: "花生", remark: "好吃的花生" });
        map.set(mapId, pos);

        pos = [];
        mapId = 2;
        pos.push({ pos: [159.33, 199.162], mapId: mapId, rowId: 1, itemId: 1, count: 1, lv: 1, rare: 1, title: "花生", remark: "好吃的花生" });
        pos.push({ pos: [-208.272, -239.303], mapId: mapId, rowId: 2, itemId: 2, count: 1, lv: 2, rare: 0.8, title: "奶酪", remark: "美味的奶酪" });
        pos.push({ pos: [0, -239.303], mapId: mapId, rowId: 3, itemId: 2, count: 1, lv: 2, rare: 0.8, title: "奶酪", remark: "美味的奶酪" });
        pos.push({ pos: [90, -239.303], mapId: mapId, rowId: 4, itemId: 2, count: 1, lv: 2, rare: 0.8, title: "奶酪", remark: "美味的奶酪" });
        pos.push({ pos: [100, -544.9], mapId: mapId, rowId: 5, itemId: 3, count: 1, lv: 2, rare: 0.5, title: "樱桃", remark: "香甜的水果" });
        pos.push({ pos: [120, -544.9], mapId: mapId, rowId: 6, itemId: 3, count: 1, lv: 2, rare: 0.5, title: "樱桃", remark: "香甜的水果" });
        pos.push({ pos: [216.907, -544.9], mapId: mapId, rowId: 7, itemId: 3, count: 1, lv: 2, rare: 0.5, title: "樱桃", remark: "香甜的水果" });
        pos.push({ pos: [169.33, 99.162], mapId: mapId, rowId: 8, itemId: 1, count: 2, lv: 1, rare: 1, title: "花生", remark: "好吃的花生" });
        map.set(mapId, pos);

        return map.get(id);
    }

    //获取地图刷新时间
    public static getResourceRefreshTime(mapId?: number): Array<any> {
        //mapId地图ID refreshTime剩余倒计时毫秒

        let token: string = Player.inst.token;

        let map: Map<string, Array<any>> = new Map();

        let refreshTime = 30 * 1000;
        let arr = [];
        arr.push({ mapId: 1, refreshTime: refreshTime });
        arr.push({ mapId: 2, refreshTime: refreshTime });
        arr.push({ mapId: 3, refreshTime: refreshTime });
        map.set("1", arr);

        return map.get(token);
    }

    //玩家拥有的配方
    public static getFormulaData() {
        //id配方ID lv配方等级 title配方名 desc描述 count数量 itype物品类型(0原料1可恢复体力)
        let arr = [];
        arr.push({ id: 1, lv: 2, count: 1, itype: 1, title: "美味拼盘", desc: "制作一份的美味拼盘，需要2个花生1个奶酪" });
        arr.push({ id: 2, lv: 1, count: 2, itype: 1, title: "美味龙虾", desc: "制作一份的美味龙虾" });
        arr.push({ id: 3, lv: 1, count: 1, itype: 1, title: "美味批萨", desc: "制作一份的美味批萨" });
        return arr;
    }

    //通过ID获取配方公式明细
    public static getFormulaDataById(id: number) {
        //合成公式 = productId产品物品ID ，productCount产出数量，productCount产品描述，itemId材料物品ID，count消耗数量 lv物品等级
        let data: Map<number, any> = new Map();
        data.set(1, {
            productId: 4,
            productCount: 1,
            lv: 1,
            productRemark: "好吃的大拼盘",
            materials: [
                { itemId: "1", count: 2 },
                { itemId: "2", count: 1 },
            ],
        });

        return data.get(id);
    }

    //获取玩家基础信息
    public static getPlayInfo() {
        let token: string = Player.inst.token;

        //hp当前体力 maxHp最大体力 ex当前经验 maxEx最大经验 lv等级 coin金币
        let play = { hp: 100, maxHp: 300, ex: 1000, maxEx: 3600, lv: 2, coin: 222 };
        return play;
    }

    //游戏全局配置数据
    public static getConfigData(): any {
        //hpConsumeRate采集体力消耗比率 exGrowRate采集经验增长比率 cHpConsumeRate合成体力消耗比率 cExGrowRate合成经验增长比率
        let value: any = { hpConsumeRate: 0.5, exGrowRate: 10, cHpConsumeRate: 0.5, cExGrowRate: 10 };
        value.weather = 1; //当前天气 0晴天 1雨天 2下雪 3大风
        value.season = 0; //当前季节 0春1夏2秋3冬
        return value;
    }

    //获取全部任务数据
    public static getTaskData() {
        //id任务ID state状态（0未完成 1已完成未领取奖励 2已完成已领取奖励） title名称 desc描述
        let arr = [];
        arr.push({
            id: 1,
            state: 0,
            title: "获得1份美味拼盘",
            desc: "制作一份的美味拼盘，需要2个花生1个奶酪，通过制作1份此物品可完成任务，可通过交易方式获取，也可自行制作获取。",
        });
        arr.push({ id: 2, state: 1, title: "获得1份美味龙虾", desc: "制作一份的美味龙虾" });
        arr.push({ id: 3, state: 2, title: "获得1份美味批萨", desc: "制作一份的美味批萨" });
        arr.push({ id: 4, state: 0, title: "获得1个花生", desc: "去采集1个花生" });
        arr.push({ id: 5, state: 0, title: "获得2个花生", desc: "拥有2个花生" });
        arr.push({ id: 6, state: 0, title: "获得1个水果", desc: "去采集1个水果" });
        arr.push({ id: 7, state: 0, title: "获得1份奶酪", desc: "去获得1份奶酪" });

        return arr;
    }

    //获取玩家背包数据
    public static getBagData() {
        //id物品ID count数量 title名称 desc描述 itype物品类型(0原料1可恢复体力)
        let arr = [];
        arr.push({ id: 1, count: 3, itype: 0, title: "花生", desc: "好吃的花生" });
        arr.push({ id: 2, count: 1, itype: 0, title: "奶酪", desc: "美味的奶酪" });
        arr.push({ id: 3, count: 10, itype: 0, title: "樱桃", desc: "香甜的水果" });

        return arr;
    }

    //上传用户信息
    public static async updatePlayerInfo() {
        // let data = await NetworkUtil.post(ApiUrl.showPlayerInfo);
        let data = await NetworkUtil.post("https://v1.jinrishici.com/rensheng");
        cc.log(data);
    }

    /**
     * 获取拍卖行数据
     */
    public static getAuctionHouseData(): Array<any> {
        //id拍卖ID itemId物品ID count拍卖数量 price拍卖单价 time拍卖时间 itype物品类型 title物品名 desc物品描述
        let arr = [];
        arr.push({ id: 1, itemId: 1, count: 3, price: 3.5, time: 3, itype: 0, title: "花生", desc: "好吃的花生" });
        arr.push({ id: 2, itemId: 2, count: 10, price: 4, time: 3, itype: 0, title: "奶酪", desc: "美味的奶酪" });

        return arr;
    }
}
